define(['./../initial'], function() {
    var app = angular.module('App.prjStatus');
    app.factory('createPrjStatusChart', ['$q', 'defineTheme',
        function($q, defineTheme) {
            function initialChart(domId, dataSet, chartHeight, chartWidth) {
                domId = "#" + domId;
                var defer = $q.defer();


                defineTheme.dark();
                var chart = $(domId).highcharts();
                if (chart) {
                    chart.destroy();
                }
                $(domId).highcharts({
                    chart: {

                        type: 'line',
                        borderColor: "transparent",
                        backgroundColor: "transparent",
                        style: {
                            fontFamily: '"Microsoft Yahei", Verdana', // default font
                            fontSize: '11px'
                        },
                        margin: [5, 50, 25, 50],
                        spacing: [5, 50, 5, 50]
                    },
                    exporting: {
                        enabled: false
                    },
                    credits: {
                        enabled: false
                    },
                    title: {
                        align: 'left',
                        text: dataSet.title,
                        x: 30,
                        style: {
                            color: "#fff",
                            fontSize: "14px",
                            fontWeight: 400
                        }
                    },
                    xAxis: {
                        categories: (function() {
                            return dataSet.lastValues.map(function(item, index) {
                                return index % 5 === 0 ? item.name : "";
                            });
                        })(),
                        gridLineColor: "#fff",
                        labels: {
                            // enabled: false,
                            // rotation: 90,
                            // x: -5,
                            style: {
                                color: '#eee'
                            }
                        },
                        tickLength: 2,
                        tickmarkPlacement: 'on',
                        tickPosition: "inside",
                        lineColor: '#838383'
                    },
                    yAxis: {
                        lineWidth: 1,
                        gridLineColor: "rgba(3,3,3,0.05)",
                        lineColor: '#838383',
                        title: {
                            text: ''
                        },
                        minTickInterval: 1,
                        labels: {
                            x: -10,
                            style: {
                                color: '#eee'
                            }
                        }
                    },
                    legend: {
                        align: 'right',
                        verticalAlign: 'top',
                        floating: true,
                        borderWidth: 0,
                        y: -6,
                        style: {
                            color: "#eee",
                            fontSize: "13px",
                            fontWeight: 800
                        }
                    },
                    tooltip: {
                        enabled: false,
                        headerFormat: '<b>{point.key}</b>:',
                        pointFormat: '{point.y}mm'
                    },
                    plotOptions: {
                        line: {
                            animation: false,
                            pointPlacement: 'on'
                        },
                        series: {
                            cursor: 'pointer',
                            marker: {
                                lineWidth: 1
                            }
                        }
                    },
                    series: [{
                        name: dataSet.lastTime,
                        data: (function() {
                            return dataSet.lastValues.map(function(item) {
                                return item.value;
                            });
                        })()
                    }, {
                        name: dataSet.curTime,
                        data: (function() {
                            return dataSet.curValues.map(function(item) {
                                return item.value;
                            });
                        })()
                    }]
                });
                defer.resolve(null);
                return defer.promise;
            }
            return initialChart;
        }
    ]);
});
